package com.ctshk.app.order.goods.controller;

import com.alibaba.fastjson.JSONObject;
import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.rpc.order.goods.dto.OrderShopCustomerDTO;
import com.ctshk.rpc.order.goods.dto.ShopOrderEsDTO;
import com.ctshk.rpc.order.goods.dto.ShoppingShopStoreDTO;
import com.ctshk.rpc.order.goods.dto.StoreShopDTO;
import com.ctshk.rpc.order.goods.req.*;
import com.ctshk.rpc.order.goods.service.IShoppingShopStoreService;
import com.ctshk.rpc.order.goods.service.IShoppingShopStoreUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * <p>
 * 中旅小店--controller
 * </p>
 *
 * @author 黄利斌
 * @date 2021/6/1 9:40 上午
 */
@Api(value = "小店C端首页", tags = "小店C端首页")
@RestController
@RequestMapping(value = "/commodity/shop")
public class OrderCommodityShopController extends AppBaseController {

    @DubboReference
    private IShoppingShopStoreService shoppingShopStoreService;

    @DubboReference
    private IShoppingShopStoreUserService shoppingShopStoreUserService;

    /**
     * 去除加号
     */
    public String replacePlus(String str) {
        return str.replaceAll("\\+", "");
    }

    @ApiOperation(value = "C端-小店-订单-客户订单", notes = "C端-小店-订单-客户订单")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "C端-小店-订单-客户订单", operDesc = "C端-小店-订单-客户订单")
    @PostMapping("/customerOrder")
    public Result<PageResponse<ShopOrderEsDTO>> customerOrder(@RequestBody ShopCustomerOrderReq req){
        return shoppingShopStoreService.customerOrder(req,getShoppingShopStoreUser(getRequest()));
    }


    @ApiOperation(value = "C端-小店-店铺展示-销售额、订单、客户数", notes = "C端-小店-店铺展示-销售额、订单、客户数")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "C端小店-店铺展示-销售额、订单、客户数", operDesc = "C端小店-店铺展示-销售额、订单、客户数")
    @GetMapping("/show/{id}/{type}")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "id",name = "小店id",dataType = "Long",paramType = "path"),
            @ApiImplicitParam(value = "type",name = "查询日期：6、今日 7、昨日 8、近七天 9、近30天",dataType = "Integer",paramType = "path")
    })
    public Result<StoreShopDTO> show(@PathVariable Long id,@PathVariable Integer type){
        return shoppingShopStoreService.show(id,type,getShoppingShopStoreUser(getRequest()));
    }

    @ApiOperation(value = "C端-小店-登录-密码", notes = "C端-小店-登录-密码")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "C端小店-登录", operDesc = "C端小店-登录")
    @PostMapping("/loginAndPwd")
    public Result<ShoppingShopStoreDTO> loginAndPwd(@RequestBody ShoppingShopPwdLoginReq req){
        return shoppingShopStoreUserService.loginAndPwd(req);
    }

    @ApiOperation(value = "C端-小店-登录-验证码", notes = "C端-小店-登录-验证码")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "C端小店-登录", operDesc = "C端小店-登录")
    @PostMapping("/loginAndCode")
    public Result<ShoppingShopStoreDTO> loginAndCode(@RequestBody @Valid ShoppingShopLoginReq req){
        return shoppingShopStoreUserService.loginAndCode(req);
    }

    @ApiOperation(value = "C端-小店-设置密码", notes = "C端-小店-设置密码")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "C端小店-设置密码", operDesc = "C端小店-设置密码")
    @PostMapping("/updatePwd")
    public Result updatePwd(@RequestBody @Valid SmsCaptchaReq req) {
        return shoppingShopStoreUserService.updatePwd(req);
    }

    @ApiOperation(value = "C端-小店-小店客户统计", notes = "C端-小店-小店客户统计")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "C端-小店-小店客户统计", operDesc = "C端-小店-小店客户统计")
    @PostMapping("/customer/statistics")
    public Result<PageResponse<OrderShopCustomerDTO>> customerStatistics(@RequestBody OrderShopCustomerReq req) {
        return shoppingShopStoreUserService.customerStatistics(req,getShoppingShopStoreUser(getRequest()));
    }

    @ApiOperation(value = "C端-小店-分页查询成员管理列表", notes = "C端-小店-分页查询成员管理列表")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "C端-小店-分页查询成员管理列表", operDesc = "C端-小店-分页查询成员管理列表")
    @PostMapping("/list")
    public Result<PageResponse<ShoppingShopStoreDTO>> list(@RequestBody ShoppingShopStorePageReq pageReq) {
        return shoppingShopStoreService.findShoppingShopStoreByCondition(pageReq,getShoppingShopStoreUser(getRequest()));
    }

    @ApiOperation(value = "C端-小店-后台开通成员小店", notes = "C端-小店-后台开通成员小店")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "C端-小店-后台开通成员小店", operDesc = "C端-小店-后台开通成员小店")
    @PostMapping("/staff")
    public Result staff(@RequestBody @Valid ShoppingShopStoreAddReq req) {
        shoppingShopStoreService.staff(req, getCurrentUser(getRequest()).getId(),getShoppingShopStoreUser(getRequest()));
        return Result.success();
    }

    @ApiOperation(value = "C端-小店-后台编辑小店", notes = "C端-小店-后台编辑小店")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "C端-小店-后台编辑小店", operDesc = "C端-小店-后台编辑小店")
    @PostMapping("/updateShoppingShopStore")
    public Result updateShoppingShopStore(@RequestBody @Valid ShoppingShopStoreAddReq obj) {
        shoppingShopStoreService.updateShoppingShopStore(obj, getShoppingShopStoreUser(getRequest()));
        return Result.success();
    }

    /**
     * 邀请码获取小店来源
     *
     * @return
     */
    @ApiOperation(value = "邀请码获取小店来源", notes = "邀请码获取小店来源")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "邀请码获取小店来源", operDesc = "邀请码获取小店来源")
    @PostMapping("/invitation")
    public Result<Map<String, Object>> invitation(@RequestBody JSONObject req) {
        String code = req.getString("code");
        String name = req.getString("name");
        return shoppingShopStoreService.invitation(code, name);
    }

    /**
     * C端中旅小店获取头部信息
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id获取中旅小店头部信息(小店专用)", notes = "根据id获取中旅小店头部信息(小店专用)")
    @OperationLogAnnotation(operModul = OperationLogModel.GOODS, operType = OperationLogType.QUERY, operTitle = "根据id获取中旅小店头部信息", operDesc = "根据id获取中旅小店头部信息")
    @GetMapping("/info/{id}")
    public Result<ShoppingShopStoreDTO> info(@PathVariable Long id) {
        return shoppingShopStoreService.info(id,getShoppingShopStoreUser(getRequest()));
    }
}
